
using System;
using Gnome;
using Gdk;

namespace MyCanvas
{
	public class Romboide:Figura
	{
		private int _x;
		private int _y;
		private int _height;
		private int _width;
		
		private Gnome.CanvasPolygon _fig;
		
		private string _color;
		private string _color2;
		
		private bool _bIn;
		private bool _bDrag;
		
		private Gdk.Point _oldPoint;
		
		public Romboide(int x, int y, int w, int h)
		{
			this._x = x;
			this._y = y;
			this._height = h;
			this._width = w;
			
						
			this._color = "#000000";
			this._color2 = "#00ff00";
		}
		
		override public string toString()
		{
			return "Este es un romboide";
		}
		
		override public void draw(Canvas c)
		{
			Console.WriteLine("Dibujando el Romboide"); 
			
			this._fig = new Gnome.CanvasPolygon(c.Root());
			
	        this._fig.Points = new CanvasPoints (new double[]{
	        								this._x,this._y, 
	        								this._x+this._width,this._y, 
	        								this._x+this._width-this._height/2,this._y-this._height,
	        								this._x-this._height/2,this._y-this._height});
			
			Console.WriteLine(this._fig.Points.ToString());		
			this._fig.CanvasEvent += new Gnome.CanvasEventHandler(CanvasEvent);
						
			this._fig.OutlineColor = this._color;
			this._fig.FillColor = this._color;
       		this._fig.WidthPixels = 1;
       		this._fig.Show();
			
			
		}
		
		public void CanvasEvent(object obj, Gnome.CanvasEventArgs args)
		{
			//Console.WriteLine("Canvas Event");
			EventButton ev = new EventButton (args.Event.Handle);
			switch (ev.Type) 
			{
				case EventType.MotionNotify:
					if ( this._bDrag )
					{
						this._fig.Move(-this._oldPoint.X+ev.X,-this._oldPoint.Y+ev.Y);
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.EnterNotify:
					MouseEnter(obj,args);
					break;
	
					
				case EventType.LeaveNotify:
					MouseLeave(obj,args);
					break;
	
				case EventType.DragEnter:
					Console.WriteLine("Drag Enter");
					break;
					
				case EventType.ButtonPress:
					if ( this._bIn )
					{
						this._bDrag = true;
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.ButtonRelease:
					if ( this._bDrag )
					{
						this._fig.Move(-this._oldPoint.X+ev.X,-this._oldPoint.Y+ev.Y);
					}
					this._bDrag = false;
					break;
			}
			//Console.WriteLine(ev.Type.ToString());
		}
		
		protected void MouseEnter(object obj, Gnome.CanvasEventArgs args)
		{
			//Console.WriteLine("Entrando al Objeto");
			this._fig.OutlineColor=this._color2;
			this._bIn = true;
		}
		
		protected void MouseLeave(object obj, Gnome.CanvasEventArgs args)
		{
			//Console.WriteLine("Saliendo del Objeto");
			this._fig.OutlineColor=this._color;
			this._bIn = false;
		}
		
	}
}
